/**
 * 用户管理管理初始化
 */
var Hhtbusers = {
    id: "HhtbusersTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Hhtbusers.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '序号', field: 'userId', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    return index+1;
                }
            },
            {title: '手机号', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '用户名', field: 'userName', visible: true, align: 'center', valign: 'middle'},
            {title: '密码', field: 'password', visible: false, align: 'center', valign: 'middle'},
            {title: '安全码', field: 'salt', visible: false, align: 'center', valign: 'middle'},
            {title: '支付密码', field: 'payPwd', visible: false, align: 'center', valign: 'middle'},
            {title: '用户类型', field: 'userType', visible: true, align: 'center', valign: 'middle',formatter:Hhtbusers.userType},
            {title: '会员头像', field: 'userPhoto', visible: false, align: 'center', valign: 'middle'},
            {title: '账号状态', field: 'userStatus', visible: false, align: 'center', valign: 'middle',formatter:Hhtbusers.userStatus},
            {title: '创建时间', field: 'createTime', visible: false, align: 'center', valign: 'middle'},
            {title: '是否允许转换', field: 'isOperation', visible: false, align: 'center', valign: 'middle',formatter:Hhtbusers.isOperation},
            {title: '真实姓名', field: 'trueName', visible: true, align: 'center', valign: 'middle'},
            {title: '推荐人手机号', field: 'invitePhone', visible: true, align: 'center', valign: 'middle'}
    ];
};
//用户类型
Hhtbusers.userType = function(value){
    var result = '';
    if(value == 0){
        result = '初始用户';
    }else if(value == 2000){
        result = '普通用户';
    }else if(value == 5000){
        result = '主管';
    }else if(value == 10000){
        result = '经理';
    }
    return result;
}
//账号状态
Hhtbusers.userStatus= function(value){
    var result = '';
    if(value == 0){
        result = '停用';
    }else if(value == 1){
        result = '启用';
    }
    return result;
}
//是否允许转换
Hhtbusers.isOperation= function(value){
    var result = '';
    if(value == 0){
        result = '不允许';
    }else if(value == 1){
        result = '允许';
    }
    return result;
}
/**
 * 检查是否选中
 */
Hhtbusers.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Hhtbusers.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加用户管理
 */
Hhtbusers.openAddHhtbusers = function () {
    var index = layer.open({
        type: 2,
        title: '添加用户管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/hhtbusers/hhtbusers_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看用户管理详情
 */
Hhtbusers.openHhtbusersDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '用户管理详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hhtbusers/hhtbusers_update/' + Hhtbusers.seItem.userId
        });
        this.layerIndex = index;
    }
};

/**
 * 删除用户管理
 */
Hhtbusers.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/hhtbusers/delete", function (data) {
            Feng.success("删除成功!");
            Hhtbusers.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("hhtbusersId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询用户管理列表
 */
Hhtbusers.search = function () {
    var queryData = {};
    queryData['userPhone'] = $("#userPhone").val();
    queryData['userName'] = $("#userName").val();
    Hhtbusers.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Hhtbusers.initColumn();
    var table = new BSTable(Hhtbusers.id, "/hhtbusers/list", defaultColunms);
    table.setPaginationType("server");
    Hhtbusers.table = table.init();
});

/**
 * 打开查看用户推荐列表
 */
Hhtbusers.openHhtbusersInvited = function () {
    if (this.check()) {
        window.location.href="/hhtbusers/invitedList/"+Hhtbusers.seItem.userId
    }
};
